package net.oschina.app;

import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.robotium.solo.Solo;

/**
 * Created by Aaron on 2017/10/29.
 */

public class SoloWrap {
    private Solo solo;

    public SoloWrap(Solo solo){
        this.solo = solo;
    }

    public View findById(String id){
        solo.waitForView(solo.getView(id),5000,false);
        return solo.getView(id);
    }

    public View findById(String id, int index){
        solo.waitForView(solo.getView(id),5000,false);
        return solo.getView(id,index);
    }

    public TextView findByText(String text){
        solo.waitForText(text,0,5000);
        return solo.getText(text);
    }

    public View findByClass(Class cls,int index){
        return solo.getView(cls,index);
    }

    public void clickOnText(String text){
        Log.i("ACTION","点击文本:"+text);
        solo.clickOnText(text);
    }

    public void click(View view){
        Log.i("ACTIOn","点击控件：" + view.getId());
        solo.clickOnView(view);
    }

    public void enterText(EditText et,String text){
        Log.i("ACTIOn","输入框输入文本：" + text);
        solo.enterText(et,text);
    }

    public void clear(EditText et){
        Log.i("ACTIOn","清空输入框文本");
        solo.clearEditText(et);
    }

    public EditText getEditText(int index){
        return solo.getEditText(index);
    }

    public void goBack(){
        solo.goBack();
    }

    public void clickOnListItem(int index){
        solo.clickInList(index - 1);
    }

    public String getText(TextView view){
        return view.getText().toString();
    }

    public boolean searchText(String text){
        return solo.searchText(text);
    }

}
